<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Home\Controller;
use Home\Controller\BaseController;

class SearchController extends BaseController{
    //put your code here
    public function _initialize(){
        parent::_initialize();
    }
    
    
    public function  index(){
        $keys = I('keys');
        $type = I('type');
        $orders = I('order');
        
        switch ($orders) {
            case 'jg':
                $order = "goods_is_index desc,goods_price desc";
                break;
            case 'xl':
                $order = "goods_is_index desc,goods_hits desc";
                break;
            case 'rq':
                $order = "goods_is_index desc,goods_hits desc,goods_price desc";
                break;
            default:
                $order = "goods_is_index desc,goods_id";
                break;
        }
        
        $where['goods_title'] = array('like',"%".$keys."%");
        $where['goods_sale'] = 1;
        $where['goods_state'] = 1;
        $goods = M('Goods');
        $count= $goods->where($where)->count();// 查询满足要求的总记录数
        $this->assign('count',$count);
        $Page= new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $arr = $goods->where($where)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('orders',$orders);
        $this->assign('arr',$arr);
        $this->assign('page',$show);
        $this->assign('keys',$keys);
        $this->display();
        
    }
    
}
